package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.service.CustomerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    CustomerService customerService;
    /**
        方法的作用:
        开发时间： 2023-02-10 18:29
        是否已经开发完毕：
        是否有功能可以拓展：
        接口功能：客户列表分页
        输入参数Integer page, Integer rows, String  customerName
    */

    @PostMapping("/list")
    public Map<String,Object> PageInfoCustomer(Integer page, Integer rows,String customerName){
        Page<Customer> customerPage = new Page<>(page,rows);
        IPage<Customer> customerIPage=customerService.PageInfoCustomer(customerPage,customerName);
        List<Customer> list = customerIPage.getRecords();
        System.out.println(list);
        HashMap<String,Object> map = new HashMap<>();
        map.put("total",customerIPage.getTotal());
        map.put("rows",customerIPage.getRecords());
        return map;
    }

    @PostMapping("/save")
    public ServiceVO saveCustomer(Customer customer){
        ServiceVO serviceVO = customerService.saveCustmomer(customer);
        return serviceVO;
    }

    @PostMapping("/delete")
    public ServiceVO deleteCustomer(String ids){
        ServiceVO serviceVO = customerService.deleteCustomer(ids);
        return serviceVO;
    }

    /**
        方法的作用:  销售出库下拉列表
        开发时间： 2023-02-11 15:51
        是否已经开发完毕：
        是否有功能可以拓展：
    */
    @PostMapping("/getComboboxList")
    public List<Customer> ListCustomer(String CustomerName){
        List<Customer> customerList = customerService.ListCustomer(CustomerName);
        return customerList;
    }


}
